from flask import g, session, url_for, redirect
import functools


""" 定义的验证登录状态的装饰器 """
def login_required(fun):
    @functools.wraps(fun)
    def login(*args, **kw):
        if "user_id" in session:
            g.user_id = session['user_id']   
            if g.user_id:
                return fun(*args, **kw)
        return redirect(url_for('admin.login'))
    return login